<template>
    <view>
        <nav-bar></nav-bar>
        <view class="mybox">
            <!-- 用户信息 s -->
            <view class="mymessage">
                <view style="height: 100%;width: 50%;display: flex;align-items: center;justify-content: center;" v-if="isLogin == false">
                    <u-button type="success" style="width: 80%;" @click="login">登录</u-button>
                </view>
                <view v-else @click="mydata">
                    <view class="textSty">
                        <!-- 回收员姓名 -->
                        {{userInfo.nickname}}
                        <text class="phone" v-if="is_hs == 2 && userInfo.status == 1 && userInfo.is_check == 1">(分销员)</text>
                        <image class="img" src="../../static/img/myhome/edit-02@3x.png"></image>
                    </view>
                    <view class="phone">{{userInfo.mobile || ""}}</view>
                </view>
                <view style="padding-top: 20rpx">我的积分：{{userInfo.point || 0}}</view>
                <image class="userimg" :src="userInfo.avatar || '../../static/img/navimg/Tab-icon-Active-04@3x.png'" mode=""></image>
            </view>
            <!-- 用户信息 e -->
            <!-- 环保金 s -->
            <view class="mymoney">
                <view class="mymoneyson">
                    <p class="mymon">我的环保金</p>
                    <p class="mymonn">￥<span class="text-style-1">{{userInfo.runbao || "0.00"}}</span></p>
                    <button class="sebutton" @click="mybalance">查看详情</button>
                    <i class=".sanj"></i>
                </view>
            </view>
            <!-- 环保金 e -->
            <view class="gotoshop" @click="toshop">
                <image class="img" src="https://re.gxqichang.cn/mini/myhome/my-shangcheng@3x.png" alt="error">
                </image>
                <view class="textbutton">
                    <text class="text">积分可兑换礼品</text>
					 <view class="point">￥{{userInfo.point || "0.00"}}</view>
                    <button class="button">进入积分商城</button>
                </view>
            </view>
            <!-- 列表 s -->
            <view class="mysetting">
                <view class="order" @click="gettabindx(2)">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-fuwudingdan@3x.png"></image>
                        <span>服务订单</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
                <view class="order" @click="toOrderTotal()">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-fuwudingdan@3x.png"></image>
                        <span>订单统计</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
                <view class="order" @click="toExchange_record">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-huangou@3x.png"></image>
                        <span>换购记录</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
                <view class="order" @click="toPoint_record">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-huangou@3x.png"></image>
                        <span>积分记录</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
                <view class="order" @click="toCard">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-yhk@3x.png" mode="widthFix"></image>
                        <span>银行卡</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
				<view class="order" @click="toApply(2)" v-if="is_hs == 0">
				
                <!-- <view class="order" @click="toApply(2)" v-if="is_hs != 2 && userInfo.status == 1 && userInfo.is_check == 1"> -->
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-fxsq@3x.png" mode="widthFix"></image>
                        <span>分销申请</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
                <view class="order" @click="toApply(1)" v-if="is_hs == 0">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-hsd@3x.png" mode="widthFix"></image>
                        <span>回收点入驻申请</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
                <view class="order" @click="toDistribution" v-if="is_hs == 2 && userInfo.status == 1 && userInfo.is_check == 1">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-fxzx@3x.png"></image>
                        <span>分销中心</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
                <view class="order" @click="toShare" v-if="is_hs == 2 && userInfo.status == 1 && userInfo.is_check == 1">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-ewm@3x.png"></image>
                        <span>分享二维码</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
                
                <view class="order" @click="toHangList">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-hsd@3x.png" mode="widthFix"></image>
                        <span>挂起订单</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view>
<!--                <view class="order" @click="scanCode">
                    <view class="order-disp">
                        <image class="orderimg1" src="../../static/img/myhome/my-icon-hsd@3x.png" mode="widthFix"></image>
                        <span>扫码下单</span>
                    </view>
                    <image class="orderimg2" src="../../static/img/myhome/my-list-more@3x.png" mode=""></image>
                </view> -->
                
            </view>
            <!-- 列表 e -->

        </view>

        <!-- 自定义tabbar s -->
        <tab-bar @clicktabindex="gettabindx"></tab-bar>
        <!-- 自定义tabbar e -->

        <!-- <u-tabbar
            :list="tabBarList"
            active-color="#1bc078"
            inactive-color="#cccccc"
        >
        </u-tabbar> -->
    </view>
</template>

<script>
    export default {
        data() {
            return {
                // tabBarList: [],
                isLogin: false,
                userInfo: {},
                shaerShow: false,
                is_hs: null,
            }
        },
        mounted() {
            console.log(this.$store.state.userInfo,888889);
            if(!this.$u.test.isEmpty(this.$store.state.userInfo)) {
                this.isLogin = true
                this.userInfo = this.$store.state.userInfo
                uni.showLoading({
                    title: '加载中'
                });
                this._getInfo()
            }
        },
        methods: {
            login() {
                var _this = this
                wx.getUserProfile({
                    lang: 'zh_CN',
                    desc: '用于完善会员资料',
                    success(res){
                        uni.login({
                          provider: 'weixin',
                          success(loginRes) {
                              uni.showLoading({
                                  title: '正在登陆'
                              });
                              _this._postWxapplogin(loginRes.code, res.userInfo)
                          },
                          fail(e) {}
                        });
                    },
                    fail(e){}
                })
            },
            // 登录api
            _postWxapplogin(code, userInfo) {
                let p = {
                    code: code,
                    userInfo: userInfo,
                }
                if(!this.$u.test.isEmpty(this.$store.state.invitecode)) {
                    p.invitecode = this.$store.state.invitecode;
                }
                this.$u.api.postWxapplogin(p).then(res => {
                    this.isLogin = true;
                    this.userInfo = res.info;
                    uni.setStorageSync('session_key', res.info.session_key);
                    this.$store.commit('setSessionKey', res.info.session_key)
                    // this.$store.commit('setUserInfo', res.info)
                    // uni.setStorageSync('userInfo', res.info);
                    this._getInfo()
                    uni.hideLoading();
                }).catch(e => {
                    uni.showToast({
                        title: e.msg,
                        duration: 1000,
                        icon: 'none'
                    });
                })
            },
            // 用户信息api
            _getInfo(key) {
                this.$u.api.getInfo().then(res => {
                    this.userInfo = res;
                    this.is_hs = res.is_hs;
                    uni.hideLoading();
                    uni.setStorageSync('is_hs', res.is_hs);
                    this.$store.commit('setUserInfo', res)
                    uni.setStorageSync('userInfo', res);
                    this.$store.commit('setIsUserEdit', 0);

                    if(this.is_hs == 1 || this.is_hs == 3 || this.is_hs == 5) {
                        uni.reLaunch({
                            url: '/homepage/Test/Home/Home'
                        });
                        this.$store.commit('changeactive', 0)
                    } else {
                        if ( this.$u.test.isEmpty(res.mobile) || this.$u.test.isEmpty(res.id_card) ) {
                            uni.showModal({
                                title: '提示',
                                content: '请先完善个人信息',
                                showCancel: false,
                                success: function success (res) {
                                    if ( res.confirm ) {
                                        uni.navigateTo({
                                            url: '../Myhome/predata'
                                        });
                                    }
                                }
                            });
                        }else if(this.$u.test.isEmpty(res.zhifupass)) {
                            uni.showModal({
                                title: '提示',
                                content: '是否前去设置支付密码',
                                success: function (res) {
                                    if (res.confirm) {
                                        uni.navigateTo({
                                            url: '../Myhome/predata'
                                        });
                                    } else if (res.cancel) {
                                    }
                                }
                            });
                        }
                    }
                }).catch(e => {})
            },
            // 跳转服务订单
            gettabindx(index) {
                this.$parent.$refs.tabbar.clicktabbars(index)
                this.$emit('index', index)
               /*
               uni.navigateTo({
                   url: '../My_order/orderlists'
               })
               */
            },
            // 跳转余额
            mybalance() {
                uni.navigateTo({
                    url: '../My_environmental/myenvironmental'
                })
            },
            // 跳转至商城
            toshop() {
                uni.redirectTo({
                    url: '../../shop/pages/index/index'
                })
            },
            // 跳转个人信息
            mydata() {
                uni.navigateTo({
                    url: '../Myhome/predata'
                })
            },
            // 跳转换购记录
            toExchange_record() {
                uni.navigateTo({
                    url: '../Myhome/Exchange_record'
                })
            },
            // 跳转积分记录
            toPoint_record() {
                uni.navigateTo({
                    url: '../Myhome/Point_record'
                })
            },
            toDistribution() {
                uni.navigateTo({
                    url: '../Myhome/distribution'
                })
            },
            toOrderTotal(){
                uni.navigateTo({
                    url: '../Myhome/orderTotal'
                })
            },
            // 分享
            toShare() {
                uni.navigateTo({
                    url: '../Myhome/share'
                })
            },
            toCard() {
                uni.navigateTo({
                    url: '../Myhome/card'
                })
            },
            toApply(type) {
                // if(this.userInfo.is_check == 1 && type == 2) {
                //     uni.showModal({
                //         title: '提示',
                //         content: '正在审核中，请耐心等待',
                //         showCancel: false,
                //         success: function (res) {
                //             if (res.confirm) {

                //             }
                //         }
                //     });
                //     return;
                // }
                uni.navigateTo({
                    url: '../Myhome/apply?type=' + type
                })
            },
            //20220905
            toHangList(){
                uni.navigateTo({
                    url: '../../mend/scan_user/hangList'
                })
            },
            scanCode(){
                //这里菜单用作测试，正式上线不需要
                uni.navigateTo({
                    url: '../../mend/scan_user/scanOrder?hang=0&server_id=0'
                })
            }
        },
        onPullDownRefresh() {
            uni.stopPullDownRefresh()
        }
    }
</script>

<style lang="scss" scoped>
	.point{
		    display: flex;
		    justify-content: center;
		    color: #ffff;
		    font-size: 36rpx;
		    margin-top: 20rpx;
	
	}
    .mybox {
        padding: 60rpx;
        background-color: #FFFFFF;
        min-height: 100vh;
    }

    .mymoney,
    .gotoshop,
    .mysetting {
        margin-top: 60rpx;
    }

    // 用户信息 s
    .mymessage {
        position: relative;
        width: 611rpx;
        height: 144rpx;

        .textSty {
            height: 48rpx;
            font-family: PingFang-SC-Heavy;
            font-size: 50rpx;
            font-weight: 600;
            line-height: 38rpx;
            color: #191919;

            .img {
                width: 40rpx;
                height: 40rpx;
                margin: 0 0 10rpx 10rpx;
            }
        }

        .phone {
            width: 200rpx;
            height: 22rpx;
            font-family: PingFang-SC-Bold;
            font-size: 28rpx;
            font-weight: normal;
            font-stretch: normal;
            line-height: 48rpx;
            letter-spacing: 0rpx;
            color: #999999;
            margin-top: 30rpx;
        }

        .userimg {
            position: absolute;
            top: 0;
            right: 0;
            height: 140rpx;
            width: 140rpx;
            border-radius: 50%;
            border: 10rpx solid #FFFFFF;
            box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1)
        }
    }

    // 用户信息 e

    // 环保金 s
    .mymoney {
        position: relative;
        width: 630rpx;
        height: 220rpx;
        background-color: #fffef4;
        border-radius: 20rpx;
        border: solid 2rpx #f7f5e0;

        .mymoneyson {
            margin: 53rpx 43rpx;

            .mymon {
                font-family: PingFang-SC-Bold;
                font-size: 28rpx;
                font-weight: normal;
                font-stretch: normal;
                line-height: 29rpx;
                letter-spacing: 0rpx;
                color: #846252;
            }

            .mymonn {
                font-family: PingFang-SC-Heavy;
                font-size: 40rpx;
                font-weight: normal;
                font-stretch: normal;
                line-height: 29rpx;
                letter-spacing: 0rpx;
                color: #ff4200;
                margin-top: 34rpx;

                .text-style-1 {
                    font-family: PingFang-SC-Heavy;
                    font-size: 70rpx;
                    font-weight: normal;
                    letter-spacing: 0rpx;
                    color: #ff4200;
                }
            }

            .sebutton {
                position: absolute;
                top: 75rpx;
                right: 40rpx;
                width: 190rpx;
                height: 70rpx;
                background-image: linear-gradient(90deg,
                        #ffca4b 0%,
                        #ff4200 100%),
                    linear-gradient(#ff5400,
                        #ff5400);
                background-blend-mode: normal,
                    normal;
                box-shadow: 0rpx 15rpx 30rpx 0rpx rgba(255, 68, 1, 0.25);
                border-radius: 35rpx;
                font-family: PingFang-SC-Bold;
                font-size: 28rpx;
                line-height: 70rpx;
                letter-spacing: 0rpx;
                color: #ffffff;
            }

            .sanj {
                position: absolute;
                top: 97rpx;
                right: 40rpx;
                width: 0;
                height: 0;
                border: 14rpx solid #0000FF;
                border-color: transparent transparent transparent #FFFFFF;
            }
        }
    }

    // 环保金 e

    // 跳转商城 s
    .gotoshop {
        display: flex;
        align-items: center;
        height: 220rpx;
        border-radius: 20rpx;
        background-size: contain;

        .img {
            position: absolute;
            width: 628rpx;
            height: 220rpx;
        }

        .textbutton {
            z-index: 1;

            .text {
                font-size: 36rpx;
                color: #ffffff;
                margin: 48rpx 0 0 68rpx;
                z-index: 12;
            }

            .button {
                margin-top: 18rpx;
                width: 251rpx;
				margin-left: 60rpx;
                height: 60rpx;
                background-color: #faa152;
                border-radius: 30rpx;

                font-size: 28rpx;
                color: #ffffff;
                line-height: 60rpx;
            }
        }
    }

    // 跳转商城 e

    // 列表 s
    .mysetting {
        width: 630rpx;
        // height: 224rpx;
        background-color: #ffffff;
        box-shadow: 0rpx 0rpx 25rpx 0rpx rgba(0, 0, 0, 0.05);
        border-radius: 20rpx;

        .order {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin: 0 30rpx;
            height: 112rpx;

            .order-disp {
                display: flex;
                align-items: center;
            }

            .orderimg1 {
                width: 56rpx;
                height: 56rpx;
                background-color: #eaf7fa;
                border-radius: 28rpx;
                margin-right: 29rpx;
            }

            span {
                // margin-right: 320rpx;
                font-family: PingFang-SC-Bold;
                font-size: 32rpx;
                font-weight: 600;
                color: #191919;
            }

            .orderimg2 {
                width: 30rpx;
                height: 30rpx;
            }
        }
        .order+.order {
            border-top: 1px solid #EEEEEE;
        }
    }

    // 列表 e
</style>
